package net.sf.jgcs.adapters;

import java.util.ArrayList;
import java.util.List;

import net.sf.jgcs.membership.MembershipListener;

public class ExtendedMembershipListener implements MembershipListener{

	private List<MembershipListener> listeners = null;
	
	public ExtendedMembershipListener(){
		listeners = new ArrayList<MembershipListener>();
	}
	
	public void add(MembershipListener listener){
		this.listeners.add(listener);
	}
	
	public void remove(MembershipListener listener){
		this.listeners.remove(listener);
	}
	
	public void removeAll(){
		this.listeners.clear();
	}
	
	public List<MembershipListener> getListeners(){
		//return a clone because the list should be only modified inside the class...
		return new ArrayList<MembershipListener>(listeners);
	}

	public void onExcluded() {
		for (MembershipListener listener : listeners) {
			listener.onExcluded();
		}
	}

	public void onMembershipChange() {
		for (MembershipListener listener : listeners) {
			listener.onMembershipChange();
		}
	}
}